using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Beta_fundies_controls_comments_Comments : Controls.DataManagerQuoteControl
{
    protected override void ItemChanged()
    {
        if (CurrentQuote != null)
        {
            SetDataSource(DAL.Comments.GetByQuote(CurrentQuote));
        }
        else
        {
            SetDataSource(null);
        }
    }

    public void SetDataSource(List<DAL.Comment> datasource)
    {
        gridComments.DataSource = datasource;
        gridComments.DataBind();
    }

    private bool userRetrieved = false;

    private DAL.User _CurrentUser;
    private DAL.User CurrentUser
    {
        get
        {
            if (userRetrieved == false)
            {
                _CurrentUser = Managers.UserLoginManager.CurrentUser;
                userRetrieved = true;
            }
            return _CurrentUser;
        }
    }

    bool ipRetrieved = false;
    private string _currentIP;
    private string CurrentIP
    {
        get
        {
            if (ipRetrieved == false)
            {
                _currentIP = HttpContext.Current.Request.UserHostAddress;
                ipRetrieved = true;
            }
            return _currentIP;
        }
    }

    protected bool ShowEditPanel(string IPAddress, DateTime datePosted)
    {
        if (CurrentUser != null && CurrentUser.HasPermissions(DAL.User.UserStatus.Moderator))
        {
            return true;
        }
        else
        {
            if (datePosted >= DateTime.Now.AddHours(-1) && !String.IsNullOrEmpty(IPAddress))
            {
                return IPAddress.Equals(CurrentIP);
            }
        }
        return false;
    }

    protected string GetBgColor(bool visible)
    {
        if (CurrentUser != null && CurrentUser.HasPermissions(DAL.User.UserStatus.Moderator))
        {
            if (visible)
            {
                return "#FFFFFF";
            }
            else
            {
                return "#FF0000";
            }
        }
        else
        {
            return "#FFFFFF";
        }
    }

    public bool ShowQuoteLink
    {
        get
        {
            if (ViewState["ShowQuoteLink"] != null)
            {
                return (bool)ViewState["ShowQuoteLink"];
            }
            else
            {
                return false;
            }
        }
        set
        {
            ViewState["ShowQuoteLink"] = value;
        }
    }

    protected bool ShowModPanel()
    {
        return CurrentUser != null && CurrentUser.HasPermissions(DAL.User.UserStatus.Moderator);
    }
}
